package Bussiness;

import Model.BangDiem;
import Model.KhoaHoc;
import Model.LopHoc;
import Model.MonHoc;
import Model.SinhVien;
import Model.Users;

import java.util.Vector;
import javax.swing.table.AbstractTableModel;

/**
 * Set table content
 * @author Nhóm java lớp PNV2T - Nguyễn Thị Lệ Đài - Nguyễn Chí Hướng
 */
public class TableModel extends AbstractTableModel {
    
    /** Creates a new instance of TableModel */
    Vector vec=null;
    Vector vecHeader=null;
    public static final int Type_DanhSachKhoaHoc 	= 1;
    public static final int Type_DanhSachLopHoc 	= 2;
    public static final int Type_DanhSachLopHocChiTiet 	= 3;
    public static final int Type_DanhSachSinhVien 	= 4;
    public static final int Type_BangDiemSinhVien 	= 5;
    public static final int Type_DanhSachMonHoc 	= 6;
    public static final int Type_DanhSachUser 	= 7;
    
    private int type = 0;
    public TableModel(Vector vec,Vector vecHeader,int type) {
        this.vec=vec;
        this.vecHeader=vecHeader;
        this.type=type;
    }
    
    public int getRowCount() {
        return vec.size();
    }
    
    public int getColumnCount() {
        return vecHeader.size();
    }
    
    public Object getValueAt(int x, int y) {
        if (type==Type_DanhSachKhoaHoc)
            return getDanhSachKhoaHoc(x,y);
        if (type==Type_DanhSachLopHoc)
            return getDanhSachLopHoc(x,y);
        if (type==Type_DanhSachLopHocChiTiet)
            return getDanhSachLopHocChiTiet(x,y);
        if (type==Type_DanhSachSinhVien)
            return getDanhSachSinhVien(x,y);
        if (type==Type_BangDiemSinhVien)
            return getBangDiemSinhVien(x,y);
        if (type==Type_DanhSachMonHoc)
            return getDanhSachMonHoc(x,y);
        if (type==Type_DanhSachUser)
                return getDanhSachUser(x,y);
        return 0;
    }
    
    private Object getDanhSachUser(int x, int y) {
    	Users user = (Users)vec.elementAt(x);
    	if (y==0)
            return user.getTaiKhoan();
        return 0;
	}

	public Object getDanhSachKhoaHoc(int x, int y){
        KhoaHoc KH = (KhoaHoc)vec.elementAt(x);
        if (y==0)
            return KH.getTenKhoa();
        return 0;
    }
    public Object getDanhSachLopHoc(int x, int y){
        LopHoc lop = (LopHoc)vec.elementAt(x);
        if (y==0)
            return lop.getTenLop();
        return 0;
    }
    public Object getDanhSachLopHocChiTiet(int x, int y){
        LopHoc lop = (LopHoc)vec.elementAt(x);
        if (y==0)
            return lop.getID();
        if (y==1)
            return lop.getTenLop();
        if (y==2)
            return lop.getHeDaoTao();
        if (y==3)
            return lop.getChuNhiem();
        if (y==4)
            return lop.getLopTruong();
        return 0;
    }
    
    public Object getDanhSachSinhVien(int x, int y){
        SinhVien sv = (SinhVien)vec.elementAt(x);
        if (y==0)
            return sv.getID();
        if (y==1)
                return sv.getMaSV();
        if (y==2)
                return sv.getTen();
        if (y==3)
            return sv.getQueQuan();
        if (y==4)
            return sv.getNgaySinh();
        if (y==5)
            return sv.getGioiTinh();
        if (y==6)
            return sv.getTonGiao();
        return 0;
    }
    
    public Object getBangDiemSinhVien(int x, int y){
        BangDiem diem = (BangDiem)vec.elementAt(x);
        if (y==0)
            return diem.getTenMon();
        if (y==1)
            return diem.getDiemKiemTra();
        if (y==2)
            return diem.getDiemChuyenCan();
        if (y==3)
            return diem.getDiemThi();
        if (y==4)
            return diem.getDiemTongKet();
        return 0;
    }
    public Object getDanhSachMonHoc(int x, int y){
        MonHoc monhoc = (MonHoc)vec.elementAt(x);
        if (y==0)
            return monhoc.getTenMon();
        if (y==1)
            return monhoc.getKyHoc();
        if (y==2)
            return monhoc.getNamHoc();
        if (y==3)
            return monhoc.getSoTinChi();
        return 0;
    }
    
    public String getColumnName(int columnIndex){
        return (String)vecHeader.elementAt(columnIndex);
    }
    
}
